<template>
  <div class="login-box">
    <div class="content">
      <h3>China Tide</h3>
      <el-form
        class="form"
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        inline-message
      >
        <el-form-item label-width="auto" prop="account">
          <el-input
            type="text"
            v-model="ruleForm.account"
            placeholder="请输入用户名"
            clearable
          >
            <template slot="prepend">账号 </template>
          </el-input>
        </el-form-item>
        <el-form-item label-width="auto" prop="password">
          <el-input
            type="password"
            v-model="ruleForm.password"
            placeholder="请输入密码"
            clearable
          >
            <template slot="prepend">密码</template>
          </el-input>
        </el-form-item>
       
        <el-form-item label-width="auto">
          <el-button type="primary" class="btn" @click="submitForm('ruleForm')"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="mask-layer"></div>
  </div>
</template>
<script>
import { mapMutations } from "vuex";
import {Toast} from "vant";
export default {
  data() {
    return {
      ruleForm: {
        account: "",
        password: "",
      },
      rules: {
        account: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  
  methods: {
    ...mapMutations(["changeLogin"]),
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.http.post("/api/mfh/user/login", this.ruleForm).then((res) => {
            this.changeLogin({ token: res.data.data});
            this.$router.push("/ground");
            Toast("登录成功！");
          });
        } else {
        }
      });
    },
  },
};
</script>
<style scoped>
.login-box {
  height: 100vh;
  background: url("../assets/images/3.jpg");
  background-position: center center;
  background-size: cover;
  background-repeat: no-repeat;
  position: relative;
  display: flex;
  flex-direction: column;
  /* justify-content: center; */
  padding: 0 10px;
}
.login-box .mask-layer {
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  background: rgba(255, 255, 255, 0.5);
  z-index: 100;
}
.login-box .form {
  width: 100%;
  margin: auto;
}

.btn {
  width: 100%;
  letter-spacing: 5px;
}

.content {
  z-index: 999;
  margin-top: 50%;
  display: flex;
  flex-direction: column;
  align-content: center;
  justify-content: center;
}
h3 {
  text-align: center;
  color: rgb(27, 24, 24);
  margin-bottom: 20px;
  font-size: 28px;
  font-weight: 400;
  letter-spacing: 5px;
}
</style>
